//
// Created by xinhua on 2021/10/27.
//

#include "PerspCamera.h"

PerspCamera::PerspCamera() {
    type = GET_CLASS(__FILE__);
    name = type + "_" + id;

    fov = 45.0f;
    nearplan = 0.3f;
    farplan = 3000.0f;
}


Matrix4x4 PerspCamera::getProjectionMatrix() {
    return Matrix4x4::perspective(Angle::deg2rad(fov), WINDOW_WIDTH / WINDOW_HEIGHT, nearplan, farplan);
}

Matrix4x4 PerspCamera::getViewMatrix() {
    Vector3 target(0.0f, 0.0f, -1.0f);
    Vector3 up(0.0f, 1.0f, 0.0f);

    Matrix4x4 cameraMat = Matrix4x4::lookAt(location, target, up);
    //逆矩阵
    Matrix4x4 viewMat = cameraMat.inverse();
    return viewMat;
}

/**
 * UI
 */
void PerspCamera::drawUI() {
    Camera::drawUI();
    ImGui::SliderFloat("fov", &fov, 0.0f, 360.0f);
}

void PerspCamera::onInit() {

    Camera::onInit();
}
